/**
 * 
 */
package ch.baeni.jee.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Globale Hilfsmethoden fuer das ganze Projekt
 * 
 * @author Benjamin
 * 
 */
public class SLL_Globals {
	/**
	 * Benutzerrollen
	 * 
	 * @author Benjamin
	 * 
	 */
	public enum UserRole {
		ADMIN, USER;
	}

	/**
	 * Generiert MD5-Hash aus einem Passwort-String
	 * 
	 * @param password
	 *            Passwort im Klartext
	 * @return <code>String</code> Gehashtes Passwort
	 */
	public static String getHashCode(String password) {
		byte[] bytes = password.getBytes();
		StringBuffer hexString = new StringBuffer();
		try {
			MessageDigest algorithm = MessageDigest.getInstance("MD5");
			algorithm.reset();
			algorithm.update(bytes);
			byte[] messageDigest = algorithm.digest();
			for (int i = 0; i < messageDigest.length; i++) {
				String hex = Integer.toHexString(0xFF & messageDigest[i]);
				if (hex.length() == 1) {
					hexString.append('0');
				}
				hexString.append(hex);
			}

		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return hexString.toString();
	}
}
